<?php
namespace Home\Controller;
use Think\Controller;
class UserController extends CommonController {
    public function data_list(){
        $limit = I("pageSize", 30, "intval");
        $page = I("pageCurrent", 1, "intval");
        $search_words = I('search_words');
        if(I('tr_id')){
            $condition['us_tribe_id'] = I('tr_id');
            $condition['us_tribe_status'] = 2;
        }
        $condition['us_phone'] = array('like','%'.$search_words.'%');
        $this->assign('search_words',$search_words);
        $user_model = D("User");
        $count = $user_model->get_count($condition);
        if(I("orderField")!=null&&I("orderDirection")!=null){
            $order = I("orderField").' '.I("orderDirection");
        }
        $dataList = $user_model->get_user_list($condition, $limit, $page,'*',$order);
        $this->assign("count",$count);
        $this->assign("dataList",$dataList);
    	$this->display();
    }

    public function awardLog_list(){
        $limit = I("pageSize", 30, "intval");
        $page = I("pageCurrent", 1, "intval");
        $awardLog_model = D("AwardLog");
        if(I('type')!=null){
            $condition['aw_type'] = I('type');
        }
        if(I('us_id')){
            $condition['aw_target'] = I('us_id');
        }
        $count = $awardLog_model->get_count($condition);
        $dataList = $awardLog_model->get_award_log_list($condition, $limit, $page);
        $this->assign("count",$count);
        $this->assign("dataList",$dataList);
        $this->assign("awTypes",C("aw_type"));
        $this->display();
    }

    public function clearAward(){
        $us_id= $_GET['us_id'];
        $user = D('User')->where(array('us_id'=>$us_id))->find();
        if(!empty($user)){
             D('User')->where(array('us_id'=>$user['us_id']))->save(array('us_award_money'=>0));
             D("AwardLog")->where(array('aw_target'=>$user['us_id']))->delete();
            exit(success('成功！'));
        }else{
            exit(error('失败！'));
        }
    }
}